﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Tools.Utils
{
    public class PinyinHelper
    {
        /// <summary>
        /// 字符串转换为拼音
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string GetPinYinAll(string str)
        {
            if (string.IsNullOrWhiteSpace(str)) 
            {
                return null;
            }

            return System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(NPinyin.Pinyin.GetPinyin(str)).Trim();
        }

        /// <summary>
        /// 获取拼音首字母
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string GetPinYinInitialName(string str)
        { 
            return GetPinYinAll(str??"").Substring(0, 1); 
        }
    }
}
